layui.use(['form', 'jquery', 'jquery_cookie'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        $ = layui.jquery_cookie($);

    /**
     * 表单的submit监听
     * form.on('按钮元素的lay-filter属性值')
     */
    form.on('submit(adminPassword)', function (data) {
        // 所有表单元素的值 => data.field

        // 发送ajax请求
        $.ajax({
            type: "post",
            url: path + "/user/updatePassword",
            data: {
                userId: data.field.userId,
                newPassword: data.field.new_password,
                rePassword: data.field.re_password,
            },
            success: function (result) {
                // 判断是否修改成功
                if (result.code == 200) {
                    // 修改密码成功后，清空cookie数据，跳转到登录页面
                    layer.msg("用户密码修改成功，系统将在3秒后退出...", function () {
                        // 清空cookie
                        $.removeCookie("userId", {domain: "localhost", path: "/"});
                        $.removeCookie("nick", {domain: "localhost", path: "/"});
                        // 父窗口跳转到登录页面
                        window.parent.location.href = path + "/login"
                    })
                } else {
                    layer.msg(result.msg, {icon: 5})
                }
            }
        });

        return false;
    })

});
